<?php
namespace App\Event;

use Cake\Event\EventListenerInterface;
use Cake\ORM\TableRegistry;

class UserStatistic implements EventListenerInterface
{
    public function implementedEvents(): array
    {
        return [
            'Order.afterPlace' => ['callable' => 'updateBuyStatistic',
                    'priority' => 1
            ],
        ];
    }

    public function updateBuyStatistic($event, $data)
    {
        // Code to update statistics
        $tests = TableRegistry::getTableLocator()->get('Tests');
        $tests->query()
            ->insert(['title', 'code', 'date_time'])
            ->values(['title' => 'userStatistic',
                    'code' => $data['code'],
                    'date_time' => time()
                ])
            ->execute();
    }
}
